moddbfandomcom-20200213-history
SPR
The Sprite, or SPR, by ID Software (for 3d engines) is basicly a single or series of 2d images, with additional 3D orientation data in the header. Engines (known to me) that uses this format of sprites are Quake 1 and Quake 2, possibly also the valve Half-Life engine. ID's Sprites are indexed 8bit images using no compression, fairly easy to understand, extract data from and render. The modding community (Credits: LordHavoc) however have made some improvements to the original specifications to allow 32bit sprites, which also will be documented here. However, only modern engines such as Darkplaces, FTE QW, VengeanceR2 and such supports it. Included at the bottom is a sample project in VB. File Format in C style description, see source for more information Sprite Header typedef struct { char name4; // "IDSP" long ver1; // Version = 1 (or 32 for 32bit sprites) long type; // See below float radius; // Bounding Radius long maxwidth; // Width of the largest frame long maxheight; // Height of the largest frame long nframes; // Number of frames float beamlength; // (rarely ever used?) long synchtype; // 0=synchron 1=random (most commonly synchron) } spr_t; The size of this header is 0x24 bytes. Type of sprites: * Type 0: vp parallel upright * Type 1: facing upright * Type 2: vp parallel * Type 3: oriented * Type 4: vp parallel oriented Sprite Frames There are two types of frames. Most of them contain a single picture, but some of them (in s_torch.spr and shots.spr) contain multiple pictures associated with floating point values. The first kind of frames are marked with a leading (long) zero, followed by the picture data: long group; // Always 0 for single-picture frames picture pic; // Picture data, see below The second kind of frames are marked with a leading 0x1 or 0x10000000, followed by the number of pictures, a list of floating point values, and a list of pictures: long group; // not zero (0x1 or 0x10000000) long npics; // Number of pictures float timesnpics; // 0.0, 0.2, 0.3, ... picture picnpics; // Pictures Pictures (indexed) The format of each individual picture is given below. It contains the X and Y offsets, the width and height of the picture, followed by the list of pixels. The reference to the Quake palette is implicit and the value 0xFF denotes a transparent pixel. typedef struct { long ofsx; // horizontal offset, in 3D space long ofsy; // vertical offset, in 3D space long width; // width of the picture long height; // height of the picture char Pixelswidth*height; // array of pixels (flat bitmap) } picture; Pictures (32 bit) If the picture type is a 32bit one, identified by the file header (version: 32), we need to load the picture data slightly different. In the indexed sprites, the picture data were only an array of pixels pointing to a color table (palette), but in the 32bit version we store all values per pixel. Red, green blue and alpha. typedef struct { char r; // red char g; // green char b; // blue char a; // alpha } rgba; typedef struct { long ofsx; // horizontal offset, in 3D space long ofsy; // vertical offset, in 3D space long width; // width of the picture long height; // height of the picture rgba Pixelswidth*height; // array of rgba values } picture; A warning on 32bit sprites As clearly shown, the 32bit sprites are much larger. An indexed sprite of 50x50 pixels (2500 total) requires 2500 bytes of space for the image data. However, the 32bit rgba contains 4 variables to store picture data - so the same 50x50 pixels would require 50x50x4 bytes, a total of 10.000. So, these sprites are big! Another thing to note is that it does not appear to be possible at this time to use 24bit sprites same as the 32bit, but without the alpha values. If it were possible to use 24bit sprites, you could save 1/4th of the file size from being wasted on opaque sprites. Sample Source Code * VB: Sprite Viewer (source code) External Links * Quake Specs v3.3 Credits * VB Sprite Viewer by: Darksnow 09:10, 23 December 2006 (EDT) * IDSP specs documentation by: Authors of the Quake Specs v3.3 Category:Fileformat